package hd.cls5;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
//>>>import java.time.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class DateTest {
    public static void main(String[] args) {
        Date date = new Date();
        System.out.println(date.getTime() + " 毫秒数");
        System.out.println(date);
        System.out.println(date.getYear());
        System.out.println(date.getMonth());
        System.out.println(date.getDate());
        System.out.println(date.getDay() + ".周几");
        Calendar c = Calendar.getInstance();
        //System.out.println(c);
        //>>>
        c.set(Calendar.DAY_OF_YEAR, 300);
        c.add(Calendar.DATE, 12);
        int year = c.get(Calendar.YEAR);
        System.out.println("年：" + year);
        int month = c.get(Calendar.MONTH);
        System.out.println("月份：" + month);
        int days = c.get(Calendar.DAY_OF_YEAR);
        System.out.println("这一年过了：" + days + "天");
        System.out.println(c.getTime());
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss E");
        format.setLenient(false);//设置宽松格式 为false ...
        //format ->Date String
        //parse  String ->Date
        String str = format.format(date);
        System.out.println(str);

        String ds = "2012-2-31";
        format.applyPattern("yyyy-MM-dd");//换格式
        Date d2 = null;
        try {
            d2 = format.parse(ds);
            System.out.println(d2);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}
